<?php
if (!defined('IN_ZWS')) exit();

class PanelAction extends PublicAction {
	function index() {
		$this -> assign('nowNav', 0);
		$this -> assign('topNav', array(array('name' => '概况', 'page' => 'overview'), array('name' => '设置', 'page' => 'settings'), array('name' => '关于', 'page' => 'about')));
		$this -> display('Public:index');
	}

	function overview() {
		$M = M();
		$count = array('users' => $M -> table('zws_user') -> count(),
			'moods' => $M -> table('zws_zone_mood') -> count(),
			'comments' => $M -> table('zws_article_comment') -> count(),
			'groups' => $M -> table('zws_group_group') -> count(),
			'grades' => $M -> table('zws_group_grade') -> count(),
			'subjects' => $M -> table('zws_group_subject') -> count(),
			'categories' => $M -> table('zws_group_category') -> count(),
			'books' => $M -> table('zws_article') -> where('res=0') -> count(),
			'videos' => $M -> table('zws_article') -> where('res=1') -> count(),
			'exams' => $M -> table('zws_article') -> where('res=2') -> count(),
			);
		$this -> assign('count', $count);
		$this -> display();
	}

	function settings() {
		$mailSetting = json_decode(setting('mail_setting'), true);
		$this -> assign('mailSetting', $mailSetting);
		$this -> assign('deathTime', setting('verify_death_time'));
		$this -> assign('mgrMail', setting('mgr_mail'));
		$this -> assign('publicKey', setting('touclick_public_key'));
		$this -> assign('privateKey', setting('touclick_private_key'));
		$this -> display();
	}

	function setting() {
		setting('mail_setting', json_encode(array('host' => $this -> _post('host'),
					'address' => $this -> _post('address'),
					'user' => $this -> _post('user'),
					'pass' => $this -> _post('pass')
					)));
		setting('mgr_mail', $this -> _post('mgrMail'));
		setting('touclick_public_key', $this -> _post('publicKey'));
		setting('touclick_private_key', $this -> _post('privateKey'));
		setting('verify_death_time', intval($this -> _post('verifyDeathTime')));
		$this -> ajaxReturn('', '保存成功', 0);
	}
	function about() {
		$this -> display();
	}
}
